#!/usr/bin/env python
import os, sys

fi = sys.argv[1]

fbak = fi+'.bak'

# backup original switchtime data
if not os.path.exists(fi.replace(".txt",".txt.bak")):
    cmd = 'cp {} {}'.format(fi, fbak)
    os.system(cmd)

    fp = open(fi)
    lines = fp.readlines()

    fnew = fi+'.tmp'
    fp_new = open(fnew,'w')
    for i in range(len(lines)):
        line = lines[i]
        line.replace('\n', '')
        #    line = line.replace('-','')
        #    print(line)
        year = line[0:4]
        month = line[4:6]
        day = line[6:8]
        hour = line[9:11]
        minute = line[11:13]
        second = line[13:15]
        rest = line[15:]
        wave = line[20:]
        fp_new.writelines([year+"-"+month+"-"+day+"T"+hour+":"+minute+":"+second+rest])
        #     fp_new.writelines([year+"-"+month+"-"+day+"T"+hour+":"+minute+":"+second+ ' '+ wave + '\n'])
        #fp_new.write('{}-{}-{}T{}:{}:{} {}'.format(year,month,day,hour,minute,second,wave))
    fp_new.close()

    cmd = 'cp {} {}'.format(fnew, fi)
    os.system(cmd)

